package com.smallA.dao;


import com.smallA.po.Choice;
import com.smallA.po.Exam;
import com.smallA.po.Fill;
import com.smallA.po.ShortAnswer;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 试卷的实体类
 *
 * @author 君未洋
 */
public interface ExamMapper {

    /**
     * 查询所有的试卷类
     *
     * @param id 试卷id
     * @return 返回试卷
     */
    Exam selectExamById(int id);

    /**
     * 通过试卷id获取对应的选择题
     *
     * @param eid 试卷id
     * @return 返回选择题集合
     */
    List<Choice> selectChoiceByExamId(int eid);

    /**
     * 通过对应的题型id来获取题目
     *
     * @param topicTypeIds 对应的题型id的数组
     */
    List<Choice> selectChoiceByTypeIds(Integer[] topicTypeIds);

    /**
     * 通过试卷id获取对应的填空
     *
     * @param eid 试卷id
     * @return 返回填空题集合
     */
    List<Fill> selectFillByExamId(int eid);

    /**
     * 通过对应的题型id来获取题目
     *
     * @param topicTypeIds 对应的题型id的数组
     * @return 返回查询集合
     */
    List<Fill> selectFillByTypeIds(Integer[] topicTypeIds);

    /**
     * 通过试卷id获取对应的简答题
     *
     * @param eid 试卷id
     * @return 返回简答题集合
     */
    List<ShortAnswer> selectShortAnswerByExamId(int eid);

    /**
     * 通过对应的题型id来获取题目
     *
     * @param topicTypeIds 对应的题型id的数组
     * @return 返回查询集合
     */
    List<ShortAnswer> selectShortAnswerByTypeIds(Integer[] topicTypeIds);

    @Insert("insert into exam(teacher_id,exam_analyze,exam_score) values(#{id},#{analyze},#{score})")
    int addExam(@Param("id") int id, @Param("analyze") String analyze, @Param("score") Integer score);


    Integer selectExamByAnalyze(String analyze);

    @Update("update exam set exam_difficulty = #{value} where exam_id = #{id}")
    void updateDifficulty(@Param("value") float value, @Param("id") int id);

    /**
     * 添加一个试卷类先
     *
     * @param teacherId  教师的id
     * @param context    对该试卷的描述
     * @param difficulty 试卷的难度
     * @return
     */
    @Insert("insert into exam values (NULL,#{tid},#{analyze},#{difficulty},#{score})")
    int insertExam(@Param("tid") int teacherId, @Param("analyze") String context, @Param("difficulty") float difficulty, @Param("score") int score);

    /**
     * 通过这一堆的数据来查询试卷
     *
     * @param tid     教师id
     * @param context 试卷的基本描述
     * @param score   对应的分值
     * @return
     */
    @Select("select exam_id as id,teacher_id as teacherId,exam_analyze as analyzes,exam_difficulty as difficulty,exam_score as score " +
            "from exam where teacher_id=#{tid} and exam_analyze=#{analyze} and exam_score = #{score}")
    Exam selectExam(@Param("tid") int tid, @Param("analyze") String context, @Param("score") int score);

    @Insert("insert into exam_question values(NULL,#{id},#{type},#{eid},#{score})")
    int addQuestionInExam(@Param("eid") int eid,
                          @Param("id") int id,
                          @Param("type") int type,
                          @Param("score") float score);

    /**
     * 查询所有的试卷并展示出来
     *
     * @return 返回所有的试卷类
     */
    List<Exam> selectAllExam();

}
